package com.alipay.app.groupmeal.standard.ui.b.function.result;

import android.content.Context;
import android.view.Display;
import android.view.KeyEvent;

import com.alipay.app.groupmeal.standard.R;
import com.alipay.app.groupmeal.standard.base.BasePresentation;
import com.alipay.app.groupmeal.standard.constant.BaseConstant;
import com.alipay.app.groupmeal.standard.listener.ResultKeyEventListener;

import java.util.List;

public class ResultPre extends BasePresentation {

    private BScreenResult resultPage;

    public ResultPre(Context outerContext, Display display) {
        super(outerContext, display);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.view_presentation_result;
    }

    @Override
    protected void initView() {
        resultPage = findViewById(R.id.result_page);
    }

    @Override
    protected void initData() {

    }

    @Override
    public boolean onKeyEventEnter(KeyEvent event) {
        //结果页面
        if (resultPage != null && resultPage.isVisibility()) {
            return resultPage.dispatchKeyEvent(event);
        }
        return super.onKeyEventEnter(event);
    }

    /**
     * 失败结果页面
     * 退款失败&支付失败
     */
    public void showFailPageResult(String msg, int isFailType) {
        String title;
        if (isFailType == BaseConstant.FAIL_TYPE.PAY)
            title = "支付失败";
        else
            title = "退款失败";
        resultPage.showFail(title, msg, new ResultKeyEventListener() {
            @Override
            public void enterKey() {
                if (mKeyEventListener != null)
                    mKeyEventListener.onEnterKey(false, isFailType);
            }
        });
    }

    /**
     * 未知结果页面
     */
    public void showUnknownPageResult(String msg) {
        resultPage.showUnknown(msg, new ResultKeyEventListener() {
            @Override
            public void enterKey() {
                if (mKeyEventListener != null)
                    mKeyEventListener.onEnterKey(false, BaseConstant.FAIL_TYPE.OTHER);
            }
        });
    }

    /**
     * 支付成功结果页面
     */
    public void showPaySuccessPageResult(String amount, List<BScreenResult.ResultBean> list) {
        resultPage.showPaySuccess(amount, list, new ResultKeyEventListener() {
            @Override
            public void enterKey() {
                if (mKeyEventListener != null)
                    mKeyEventListener.onEnterKey(true, -1);
            }
        });
    }

    /**
     * 退款成功结果页面
     */
    public void showRefundSuccessPageResult(String amount, List<BScreenResult.ResultBean> list) {
        resultPage.showRefundSuccess(amount, list, new ResultKeyEventListener() {
            @Override
            public void enterKey() {
                if (mKeyEventListener != null)
                    mKeyEventListener.onEnterKey(true, -1);
            }
        });
    }

    /**
     * 设置倒计时秒数
     *
     * @param time
     */
    public void setResultPageIntervalTime(String time) {
        resultPage.setIntervalTime(time);
    }

    private ResultPreKeyEventListener mKeyEventListener;

    public void setKeyEventListener(ResultPreKeyEventListener keyEventListener) {
        mKeyEventListener = keyEventListener;
    }

    public interface ResultPreKeyEventListener {

        /**
         * @param isSuccess  是否成功
         * @param isFailType
         */
        void onEnterKey(boolean isSuccess, int isFailType);
    }

}
